﻿using GreenXi.Pages.Navig;
using GreenXi.ViewModel;
using System.Windows;
using System.Windows.Input;
using static GreenXi.ViewModel.LoginViewModel;

namespace GreenXi.Pages.Power
{

    public partial class LoginView : Window
    {
        public LoginView()
        {
            InitializeComponent();
        }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnMinimize_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            LoginViewModel loginViewModel = new();
            LoginStatus loginStatus = loginViewModel.LoginCheck(txtUser.Text, txtPassWord.Password);
            switch (loginStatus)
            {
                case LoginStatus.Success:
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.DataContext = new { UserName = txtUser.Text };
                    mainWindow.Show();
                    this.Close();
                    break;
                case LoginStatus.Error:
                    MessageBox.Show("密码错误！");
                    break;
                case LoginStatus.UsernameDoesNotExist:
                    MessageBox.Show("用户名不存在！");
                    break;
                case LoginStatus.MultipleAccounts:
                    MessageBox.Show("用户名存在多个，请联系管理员！");
                    break;
                default:
                    break;
            }
        }
    }

}
